package com.sharer.last.controller;

import com.sharer.last.base.constant.CommonConstant;
import com.sharer.last.base.model.R;
import com.sharer.last.model.vo.personDetail.PersonalDetailVO;
import com.sharer.last.model.vo.blog.NewBlogVO;
import com.sharer.last.model.vo.blog.RandomBlogVO;
import com.sharer.last.model.vo.category.CategoryVO;
import com.sharer.last.model.vo.siteSetting.SiteSettingIndexVO;
import com.sharer.last.model.vo.tag.TagVO;
import com.sharer.last.service.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 站点相关
 *
 * @ClassName IndexController
 * @Author wangjin
 * @Date 2023/5/5 21:07
 * @Description
 * @Version 1.0
 */
@RestController
@RequestMapping(CommonConstant.BLOG_FRONT_API + "/site")
public class IndexController {
    @Resource
    SiteSettingService siteSettingService;

    @Resource
    BlogService        blogService;

    @Resource
    CategoryService    categoryService;

    @Resource
    TagService         tagService;

    @Resource
    PersonalDetailService personalDetailService;

    /**
     * 获取站点配置信息、最新推荐博客、分类列表、标签云、随机博客
     *
     * @return
     */
    @GetMapping("/index")
    public R<SiteSettingIndexVO> site(@RequestHeader(value = "adminToken", defaultValue = "") String adminToken) {
        // 站点配置
        SiteSettingIndexVO siteSettingIndexVO = siteSettingService.getSiteInfo();
        // 最新推荐博客
        List<NewBlogVO> newBlogList = blogService.selectNewestRecommendBlogList(adminToken);
        // 随机博客
        List<RandomBlogVO> randomBlogList = blogService.selectRandomBlogList(adminToken);
        // 分类
        List<CategoryVO> categoryList = categoryService.selectAllList();
        // 标签
        List<TagVO> tagList = tagService.selectAllList();
        // 关于我
        PersonalDetailVO personalDetailInfo = personalDetailService.getPersonalDetailInfo();
        siteSettingIndexVO.setNewBlogList(newBlogList);
        siteSettingIndexVO.setCategoryList(categoryList);
        siteSettingIndexVO.setTagList(tagList);
        siteSettingIndexVO.setRandomBlogList(randomBlogList);
        siteSettingIndexVO.setPersonalDetail(personalDetailInfo);
        return R.success(siteSettingIndexVO);
    }
}
